package com.xms.datacore.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xms.datacore.TransactionUtil;
import com.xms.dependency.XmsDependencyException;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.Collection;
import java.util.UUID;

/**
 * <p>
 * DeleterService
 * </p>
 *
 * @author migo
 * @since 2021/9/2
 */
public class DeleterService<T> extends ServiceImpl<BaseMapper<T>, T> implements IDeleterService<T>{

    @Override
    public IService<T> getService() {
        return this;
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteById(UUID id) throws SQLException, XmsDependencyException {
        return super.removeById(id);
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteMany(Wrapper<T> queryWrapper) throws SQLException, XmsDependencyException {
        return super.remove(queryWrapper);
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteByIds(Collection<UUID> idList) throws SQLException, XmsDependencyException {
        return super.removeByIds(idList);
    }

    @Override
    public void rollBack(){
        TransactionUtil.rollBack();
    }
}
